<template>
    <el-container class="home_container">
<!--     头部区域 -->
      <el-header>
        <div >
          <img src="../assets/gouwuche.png" alt="" style="width: 20px;height: 20px;margin-left: 30px">
          <span style="margin-left: 30px">超市管理系统</span>
        </div>
        <div>
<!--          <el-tooltip content="首页" placement="bottom" effect="light">-->
<!--             <img src="../assets/shouye.png" alt="" style="width: 20px;height: 20px;margin-right: 30px" @click="toHome()">-->
<!--          </el-tooltip>-->
          <el-tooltip content="菜单" placement="bottom" effect="light">
            <img src="../assets/caidan.png" alt="" style="width: 20px;height: 20px;margin-right: 30px" @click="toEmployee()">
          </el-tooltip>
          <el-tooltip content="我的账户" placement="bottom" effect="light" >
            <img src="../assets/touxiang.png" alt="" style="width: 20px;height: 20px;margin-right: 30px" @click="toAccounts">
          </el-tooltip>
          <el-tooltip content="退出账户" placement="bottom" effect="light">
            <img src="../assets/tuichu.png" alt="" style="width: 20px;height: 20px;margin-right: 30px" @click="loginout">
          </el-tooltip>
        </div>
      </el-header>
<!--     页面主体区域 -->
      <el-container class="main-menu">
<!--       侧边栏 -->
        <el-aside style="background-color: #FFFFFF;" :width="isCollapse ? '0px' : '200px'">
<!--          <div class="toggle-button" @click="toggleCollapse">|||</div>-->
<!--          侧边栏菜单区-->
          <el-menu
            background-color="#FFFFFF"
            text-color="#000000"
            active-text-color="#409EFF"
            :unique-opened="true"
            :collapse="isCollapse"
            :collapse-transition="false"
            :router="true"
            :default-active="path">
            <!-- router属性   二级菜单路由跳转 启用该模式会在激活导航时以 index 作为 path 进行路由跳转 -->
<!--          子菜单 el-submenu  -->
            <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
<!--              -->
<!--              一级菜单模板-->
              <template slot="title">
                <i :class="iconsList[item.id]"></i>
                <span>{{item.authName}}</span>
              </template>
              <!--          子菜单 el-submenu  -->
              <el-menu-item :index="'/' + subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="saveActivate('/'+ subItem.path)">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{subItem.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
<!--        右侧内容主体-->
        <el-main>
<!--          放一个路由占位符 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
</template>

<script>
export default {
  name: 'Home',
  data () {
    return {
      // 左侧菜单数据
      menulist: [
        {
          'id': 1,
          'authName': '员工管理',
          'path': 'employees',
          'children': [{'id': 3, 'authName': '员工列表', 'path': 'employees', 'children': ''}]
        },
        {
          'id': 2,
          'authName': '商品管理',
          'path': 'goods',
          'children': [{'id': 4, 'authName': '商品列表', 'path': 'goods', 'children': ''}]
        },
        {
          'id': 3,
          'authName': '组合优惠管理',
          'path': 'discounts',
          'children': [{'id': 5, 'authName': '组合优惠列表', 'path': 'discounts', 'children': ''}]
        }
      ],
      iconsList: {
        '1': 'iconfont icon-yonghu',
        '2': 'iconfont icon-shangpin',
        '3': 'iconfont icon-youhuiquan'
      },
      isCollapse: false,
      path: ''
    }
  },
  methods: {
    loginout () {
      this.$router.push('/header')
    },
    toHome () {
      this.isCollapse = true
      this.$router.push('/header')
    },
    toEmployee () {
      this.isCollapse = false
      this.$router.push('/employees')
    },
    toAccounts () {
      this.isCollapse = true
      this.$router.push('/accounts')
    }
  }
}
</script>

<style lang="less" scoped>
.home_container {
  height: 100%;
}
.el-header {
  background-color: red;
  //background-color: #409EFF;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 0;
  span {
    // 字体颜色
    color: #fff;
    font-size: 20px;
  }
  div {
    display: flex;
    align-items: center;
  }
}
span {
  margin-left: 15px;
}
.el-aside {
  border-right: none;
}
.el-menu {
  border-right: none;
}
.el-main {
  height: 665px;
  background-color: #eaedf1;
}
.iconfont {
  margin-right: 10px;
}
.toggle-button {
  background-color: #FFFFFF;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  // 鼠标放上面变成一个小手
  cursor: pointer;
}
</style>
